#! /usr/bin/env python
# coding=utf-8

import argparse
import sys
from argparse import RawTextHelpFormatter


parser = argparse.ArgumentParser(
    description='''
    去除 基因组文件中 不好的 nt 位点

    用法:
    remove_unlike_nt.py -i Sgun_curated_v1.0.fasta -o Sgun_curated_v1.1.fasta
    ''',formatter_class=RawTextHelpFormatter)


parser.add_argument('-i',
                help='输入的原始 fasta文件')


parser.add_argument('-o',
                help='输出的fasta文件')


args = parser.parse_args()


if not args.i or not args.o:
    parser.print_help()
    sys.exit()




infile = args.i
outfile  = args.o





outfile = open(outfile,'w')

from Bio import SeqIO

s = []
for i in SeqIO.parse(infile,'fasta'):
	name = str(i.name)
	remain_seq = str(i.seq).upper().replace('C','').replace('A','').replace('G','').replace('T','').replace('N','')
	for j in remain_seq:
		if j not in s:
			s.append(j)

print(s)

for i in SeqIO.parse(infile,'fasta'):
	name = str(i.name)
	seq = str(i.seq)
	for z in s:
		seq = seq.replace(z,'N').replace(z.lower(),'n')
	outfile.write('>'+name+'\n'+seq+'\n')

outfile.close()
